<?php

// Library File
include '../lib/library.php';


$field = $_POST['field'];
$mode = $_POST['mode'];

$done = false;

if($mode == 'hide'){
	
	$query = mysql_query("SELECT $field FROM profiles WHERE user_id='$m_user_id'");
	$array = mysql_fetch_assoc($query);
	
	// if its shown, hide it
	if(!$done && $array[$field] == 1){
		$query = mysql_query("UPDATE profiles SET $field = 0 WHERE user_id='$m_user_id'");
		echo 0;
		$done = true;
	
	// if its hidden, show it
	}else if(!$done && $array[$field] == 0){
		$query = mysql_query("UPDATE profiles SET $field = 1 WHERE user_id='$m_user_id'");
		echo 1;
		$done = true;
	}
	if(!$done){
		echo 'Do Nothing';
	}
}else if($mode == 'update'){
	$value = $_POST['value'];
	
	$problem = false;
	
	if(empty($value) && $field != 'website' && $field != 'address_line2' && $field != 'phone_number'){
		$problem = true;
		$name = ucwords(str_replace('_', ' ', $field));
		$error .= ''.$name.' cannot be empty.';
	}
	
	if(!$problem){
		$query = mysql_query("UPDATE users SET $field='$value' WHERE user_id='$m_user_id'");
		echo '';
	}else{
		echo $error;
	}
}

?>